#include "imagebox.h"


namespace infinity {

ImageBox::ImageBox()
{
	m_dimension = dw::maths::Vector2f(0.0f,0.0f);
	m_upleftCorner = dw::maths::Vector2f(0.0f,0.0f);
	m_downRightCorner = dw::maths::Vector2f(0.0f,0.0f);

}

ImageBox::~ImageBox()
{

}

/*virtual*/ dw::uint32 ImageBox::collectGeometry(/*VertexBuffer* vb, IndexBuffer *ib*/std::vector<UiVertex>* vb, std::vector< dw::uint16 >* ib, const dw::maths::Vector2f& posOffset)
{

	UiVertex vertices[4];
	dw::uint16 indices[6] = {
		1, 3, 0,
		2, 3, 1
	};

	dw::maths::Vector2f tmp;

	tmp =  m_position + posOffset;
	float z =  0.0f * float(m_zOrder) / float(LAYER_COUNT);

	vertices[0].pos = dw::maths::Vector3f(tmp.x,tmp.y, z); 
	vertices[0].uv = dw::maths::Vector2f(m_upleftCorner.x,m_upleftCorner.y);// m_image .getUV(0.0f, 0.0f);

	tmp =  m_position + posOffset + dw::maths::Vector2f(m_dimension.x,0.0f);
	vertices[1].pos = dw::maths::Vector3f(tmp.x,tmp.y, z); 
	vertices[1].uv = dw::maths::Vector2f(m_downRightCorner.x,m_upleftCorner.y);// m_image.getUV(1.0f, 0.0f);

	tmp =  m_position + posOffset + dw::maths::Vector2f(m_dimension.x,m_dimension.y);
	vertices[2].pos = dw::maths::Vector3f(tmp.x,tmp.y, z); 
	vertices[2].uv = dw::maths::Vector2f(m_downRightCorner.x, m_downRightCorner.y);// m_image.getUV(1.0f, 1.0f);

	tmp =  m_position + posOffset + dw::maths::Vector2f(0.0f, m_dimension.y);
	vertices[3].pos = dw::maths::Vector3f(tmp.x,tmp.y, z); 
	vertices[3].uv = dw::maths::Vector2f(m_upleftCorner.x ,m_downRightCorner.y);// m_image.getUV(0.0f, 1.0f);

// 	vb->append(vertices, 4);
// 	ib->append(indices, 6);

	int nbvertex = vb->size();
	for(unsigned int i=0; i < 6; i++)
	{
		ib->push_back(indices[i] + nbvertex);
	}

	for(unsigned int i=0; i < 4; i++)
	{
		vb->push_back(vertices[i]);
	}

	return 2 + super::collectGeometry(vb, ib, posOffset);
}

}